//
//  KLPushListViewController.m
//  used
//
//  Created by xalo on 16/7/28.
//  Copyright © 2016年 王凯. All rights reserved.
//

#import "KLPushListViewController.h"

@interface KLPushListViewController ()<UITableViewDataSource, UITableViewDelegate>


@property (nonatomic, strong) UITableView *tableView;


@property (nonatomic, strong) KLGood *sellerModel;

@end

@implementation KLPushListViewController

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.showsVerticalScrollIndicator = NO;
        
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"YSLSpecialCell" bundle:nil] forCellReuseIdentifier:@"YSLSpecialCell_cell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"KLMyCell" bundle:nil] forCellReuseIdentifier:@"myCell"];
    
    [self setupModel];

}



- (void)setupModel {
    self.sellerModel = [[KLGood alloc] init];
    
    BmobUser *user = [BmobUser getCurrentUser];
    NSString *uname = [user objectForKey:@"uname"];
    if (uname.length) {
        
        self.sellerModel.sallername  = [user objectForKey:@"uname"];
    }else {
        self.sellerModel.sallername = user.username;
    }
    
    BmobFile *icon = [user objectForKey:@"icon"];
    self.sellerModel.userimge = icon.url;
    self.sellerModel.province = self.model.province;
    self.sellerModel.city = self.model.city;
    self.sellerModel.desc = self.model.desc;
    self.sellerModel.saleprice = self.model.saleprice;
}

#pragma mark - <UITableViewDataSource>

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }else {
        
        return self.model.imageurls.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        KLMyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
        cell.model = self.sellerModel;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }else {
        
        YSLSpecialCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YSLSpecialCell_cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.cellImage = self.model.imageurls[indexPath.row];
        return cell;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 150;
    }else {
        return self.view.height / 3;
    }
}

@end
